import time
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

# # 打开谷歌浏览器
# driver=webdriver.Chrome()
# # 打开百度网址
# driver.get("http://www.baidu.com")
# # 定位到输入框并输入内容
# driver.find_element(By.ID,'kw').send_keys('性能测试')
# # 点击百度一下
# driver.find_element(By.ID,"su").click()

# driver=webdriver.Chrome()
# driver.get("https://cn.bing.com/#")
# driver.find_element(By.ID,"sb_form_q").send_keys("自动化测试")
# driver.find_element(By.ID,"search_icon").click()

# 京东购物流程
driver=webdriver.Chrome()
driver.implicitly_wait(15)
driver.maximize_window()
driver.get("https://passport.jd.com/uc/login")
driver.find_element(By.CLASS_NAME,"login-tab-r").click()
driver.find_element(By.ID,"loginname").send_keys("xiaoqian-01")
driver.find_element(By.ID,"nloginpwd").send_keys("Test123456")
driver.find_element(By.ID,"loginsubmit").click()
driver.find_element(By.ID,"key").send_keys("秋冬外套")
driver.find_element(By.CLASS_NAME,"button").click()
# 选择图片后点击
driver.find_element(By.PARTIAL_LINK_TEXT,"Foss Phil").click()
# 切换到新的tab页
new_window = driver.window_handles[-1]
driver.switch_to.window(new_window)
# 加入购物车
driver.find_element(By.LINK_TEXT,"加入购物车").click()
driver.find_element(By.CLASS_NAME,"btn-addtocart").click()
driver.find_element(By.CLASS_NAME,"common-submit-btn").click()
# 点击去结算-新增收货人信息
# iframe弹出框的处理
iframe = driver.find_element(By.ID,"dialogIframe")  # 通过id "dialogIframe"定位到iframe
driver.switch_to.frame(iframe)  # 然后进入到iframe中进行以下定位
# 鼠标悬浮出现的下拉菜单用ActionChains
# 先定位到悬浮菜单
div = driver.find_element(By.CSS_SELECTOR,"#jd_area")
# 再将鼠标移动到悬浮菜单上
ActionChains(driver).move_to_element(div).perform()
# 在定位到相应的元素并点击
div.find_element(By.LINK_TEXT,"浙江").click()
div.find_element(By.LINK_TEXT,"杭州市").click()
div.find_element(By.LINK_TEXT,"西湖区").click()
div.find_element(By.LINK_TEXT,"北山街道").click()
driver.find_element(By.ID,"consignee_name").send_keys("小小")
driver.find_element(By.ID,"consignee_address").send_keys("双龙街189号")
driver.find_element(By.ID,"consignee_mobile").send_keys("14012341109")
driver.find_element(By.CLASS_NAME,"btn-1").click()
time.sleep(3)
driver.find_element(By.CLASS_NAME,"checkout-submit").click()
